草庐IT

java - 用 Java 编写函数?

全部标签

javascript - d3 append() 带函数参数

这个有效://Ad3.select("body").selectAll(".testDiv").data(["div1","div2","div3"]).enter().append("div").classed("testDiv",true).text(function(d){returnd;});下面的代码片段是相同的,除了追加的参数,而不是如上所述是“div”,是一个简单地返回“div”的函数(d)://Bd3.select("body").selectAll(".testDiv").data(["div1","div2","div3"]).enter().append(func

javascript - append() 不是函数 jQuery

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭7年前。Improvethisquestion我是JQuery的新手(我来自AndroidWorld),我不明白为什么我会遇到UncaughtTypeError:$list.appendisnotafunction因为我操纵两个jQuery对象(据我所知)。所以这是我的代码:functiontransformInList(items,$list

javascript - 在 dangerouslySetInnerHTML 中从 onclick 调用 React 组件函数

React新手在这里。我有一个contenteditablediv,它有dangerouslySetInnerHTML作为child,因为我需要在运行时格式化用户输入的任何内容。在HTML中的特定范围内单击时,我想setState包含组件的变量之一。这能做到吗?如果不是,我应该如何更改我的结构?代码如下:updateText:function(){vartxt=$('#text_Box').text();if(txt.indexOf('@Name')>-1){txt=txt.replace('@Name',':Name');}this.setState({userText:txt});

javascript - 页面加载一段时间后执行 JS 函数

我有javascript函数,应该在页面加载完成3秒后调用。我知道setIntervel但它会在一定时间间隔后重复执行。我希望它执行一次。有可能吗? 最佳答案 Theonloadeventfiresattheendofthedocumentloadingprocess.Atthispoint,alloftheobjectsinthedocumentareintheDOM,andalltheimages,scripts,linksandsub-frameshavefinishedloading,Afteronloadyoucanuse

Javascript:未定义为函数参数

在此page,它显示了一些示例代码,其中包含以下行:varSubject=(function(window,undefined){作为函数参数的undefined是什么? 最佳答案 这用于防止在非严格模式下覆盖undefined的值。在非严格模式下,undefined的值可以通过为其分配其他值来覆盖。undefined=true;//Oranyothervalue因此,使用undefined的值将不会按预期工作。在严格模式下,undefined是只读的,给它赋值会抛出错误。在代码中,没有传递最后一个参数的值,所以它会隐式传递为und

javascript - 在javascript setTimeout中将字符串作为函数运行?

为什么这段代码有效?setTimeout("document.body.innerHTML='TEST'",1000)不应该吗?setTimeout(function(){document.body.innerHTML='TEST'},1000)setTimeout如何将字符串转为函数? 最佳答案 引用MDN的setTimeoutdocumentationcodeinthealternatesyntaxisastringofcodeyouwanttoexecuteafterdelaymilliseconds(usingthissyn

javascript - JSDoc:箭头函数参数

我正在尝试使用JSDoc(EcmaScript2015、WebStorm12Build144.3357.8)记录我的代码。我有一个箭头函数,我想记录它的参数。这两个示例有效(我得到自动完成):/**@param{Number}num1*/vara=num1=>num1*num1;//------------------------------/**@param{Number}num1*/vara=num1=>{returnnum1*num1;};但是当我想在forEach函数中记录箭头函数时,例如,自动完成功能不起作用(以下所有情况):/**@param{Number}num1*/[]

javascript - 谷歌地图错误 - a.lng 不是函数

我计划在我的一个应用程序中使用谷歌地图“containsLocation()”API。文档链接是-https://goo.gl/4BFHCz我正在使用相同的示例。这是我的代码。Polygonarrayshtml,body{height:100%;margin:0;padding:0;}#map{height:100%;}//ThisexamplerequirestheGeometrylibrary.Includethelibraries=geometry//parameterwhenyoufirstloadtheAPI.Forexample://functioninitMap(){va

javascript - 在没有调用函数的情况下返回如何在 Javascript 中工作?

我正在学习这个site并遇到了这个问题和答案:Writeasummethodwhichwillworkproperlywheninvokedusingeithersyntaxbelow.console.log(sum(2,3));//Outputs5console.log(sum(2)(3));//Outputs5//答案functionsum(x){if(arguments.length==2){returnarguments[0]+arguments[1];}else{returnfunction(y){returnx+y;};}}我理解if语句中的代码,但不理解else语句中的代

javascript - 为什么我必须将 async 关键字放在具有 await 关键字的函数中?

我只想等待一个进程完成,不想让函数异步。请看下面的代码。我必须使getUserList异步,因为函数中有一个await关键字。因此,我还必须编写类似“awaitUsersService.getUserList”的代码来执行该方法,而且我还必须使父函数异步。那不是我想做的。importxrfrom'xr'//apackageforhttprequestsclassUsersService{staticasyncgetUserList(){constres=awaitxr.get('http://localhost/api/users')returnres.data}}exportdefa